package com.nbsaas.boot.example.rest.convert;

import com.nbsaas.boot.example.data.entity.Example;
import com.nbsaas.boot.example.api.domain.response.ExampleResponse;

import com.nbsaas.boot.utils.BeanDataUtils;
import com.nbsaas.boot.rest.api.Converter;
/**
* 客户案例-实体对象转化成响应对象
*/

public class ExampleResponseConvert  implements Converter<ExampleResponse,Example> {

    @Override
    public ExampleResponse convert(Example source) {
        ExampleResponse  result = new  ExampleResponse();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getCreator()!=null){
                        result.setCreator(source.getCreator().getId());
                    }
                    if(source.getExampleCatalog()!=null){
                        result.setExampleCatalog(source.getExampleCatalog().getId());
                    }

                    try {
                        if(source.getCreator()!=null){
                            result.setCreatorName(source.getCreator().getName());
                        }
                    } catch (Exception ignored) { }


                    try {
                        if(source.getExampleCatalog()!=null){
                            result.setExampleCatalogName(source.getExampleCatalog().getName());
                        }
                    } catch (Exception ignored) { }

        return result;
    }

}

